<!--包含头部文件-->
{include file="public/header" /}
<style>
    #inputBox{
        width: 100%;
        height: 40px;
        border: 1px solid cornflowerblue;
        color: cornflowerblue;
        border-radius: 20px;
        position: relative;
        text-align: center;
        line-height: 40px;
        overflow: hidden;
        font-size: 16px;
    }
    #inputBox input{
        width: 114%;
        height: 40px;
        opacity: 0;
        cursor: pointer;
        position: absolute;
        top: 0;
        left: -14%;
    }
    #imgBox{
        text-align: left;
    }
    .imgContainer{
        display: inline-block;
        width: 32%;
        height: 150px;
        margin-left: 1%;
        border: 1px solid #666666;
        position: relative;
        margin-top: 30px;
        box-sizing: border-box;
    }
    .imgContainer img{
        width: 100%;
        height: 150px;
        cursor: pointer;
    }
    .imgContainer p{
        position: absolute;
        bottom: -1px;
        left: 0;
        width: 100%;
        height: 30px;
        background: black;
        text-align: center;
        line-height: 30px;
        color: white;
        font-size: 16px;
        font-weight: bold;
        cursor: pointer;
        display: none;
    }
    .imgContainer:hover p{
        display: block;
    }
    .lubo_pic{float: left;margin: 0 auto;cursor:pointer;text-align: center;background-image: url("__STATIC__/images/default.jpg")}
</style>
<body>
<article class="page-container">
    <form class="form form-horizontal" action="" method="post" id="form-subject_items-edit">
        <input type="hidden" class="input-text" value="{$data.id}" placeholder="" id="id" name="id"/>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>淘宝ID：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$data.itemid}" placeholder="" id="itemid" name="itemid" readonly/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品名称：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$data.itemtitle}" placeholder="" id="itemtitle" name="itemtitle"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品图片：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <div class="lubo_pic" onclick="img_div(this)">
                    <img src="{$data.itempic}" width="150px" height="150px" id="img_show">
                </div>
                <input id="upload_img" name="activity_img" accept="image/*" onchange="uploadImgFile(this)" type="file" style="display: none"/>
                <input name="itempic" value="{$data.itempic}" type="hidden" />
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>淘宝/天猫：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <span class="select-box" style="width: auto">
                    <select name="shoptype" id="select_cate" class="select" style="width: auto">
                    <option value="">请选择店铺类型</option>
                    <option value="B" {if condition="$data['shoptype'] eq 'B'"}selected {/if}>天猫</option>
                    <option value="C" {if condition="$data['shoptype'] eq 'C'"}selected {/if}>淘宝</option>
                </select>
                </span>
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>月销量：</label>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="{$data.itemsale}" placeholder="请输入月销量" id="itemsale" name="itemsale"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品价格：</label>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="{$data.itemprice}" placeholder="请输入淘宝/天猫价格" id="itemprice" name="itemprice"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>排序：</label>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="{$data.sort|default='50'}" placeholder="请输入淘宝/天猫价格" id="sort" name="sort"/>
            </div>
        </div>

        <div class="row cl" id="item_content">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>推荐理由：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <textarea  name="itemdesc" cols="20" rows="3" class="textarea" placeholder="说点什么...100个字符以内" >{$data.itemdesc}</textarea>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否有优惠券：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <span class="select-box" style="width: auto">
                    <select name="coupon" id="coupon" class="select" style="width: auto">
                    <option value="1" {if condition="$data['coupon'] eq 1"}selected {/if}>有</option>
                    <option value="0" {if condition="$data['coupon'] eq 0"}selected {/if}>无</option>
                </select>
                </span>
            </div>
        </div>


        <div id="coupon-content" {if condition="$data['coupon'] eq 1"}style="display: block"{else /} style="display: none"{/if}>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券金额：</label>
                <div class="formControls col-xs-2 col-sm-2">
                    <input type="text" class="input-text" value="{$data.couponmoney}" placeholder="请输入优惠券金额" id="couponmoney" name="couponmoney"/>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券链接：</label>
                <div class="formControls col-xs-6 col-sm-6">
                    <input type="text" class="input-text" value="{$data.couponurl}" placeholder="请输入优惠券链接" id="couponurl" name="couponurl"/>
                </div>
            </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券开始时间：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text begin_time"  id="couponstarttime" name="couponstarttime" value="{$data.couponstarttime|date='Y-m-d H:i:s', ###}" >
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券结束时间：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text"class="input-text end_time"  id="couponendtime" name="couponendtime" value="{$data.couponendtime|date='Y-m-d H:i:s', ###}">
            </div>
        </div>
        </div>


        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--包含footer文件-->
{include file="public/footer" /}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__STATIC__/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="__STATIC__/layui/layui.all.js"></script>

<script type="text/javascript">


    //点击图片上传
    function img_div(e) {
        $("#upload_img").click()
    }
    //    上传图片
    function uploadImgFile(even) {
        var id = even.id;
        $.ajaxFileUpload
        (
            {
                url: '{:url("Upload/img_upload")}',//需要链接到服务器地址
                secureuri: false,
                fileElementId: id,
                dataType: 'json',
                success: function (data)  //服务器成功响应处理函数
                {
                    var path = data.data.path;
                    var host_path = data.data.host_path;
                    $("#"+id).next().val(path);
                    $("#"+id).prev().children(':first').attr('src',host_path);
                },
                error: function (data, status, e)//服务器响应失败处理函数
                {
                    layer.alert('失败',{
                        skin: 'layui-layer-molv' //样式类名 自定义样式
                        ,closeBtn: 0  // 是否显示关闭按钮
                        ,anim: 1 //动画类型
                        ,btn: '确认'//按钮
                        ,icon: 6  // icon
                    })
                }
            }
        )
        return false;

    }

    $(function () {

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        $("#form-subject_items-edit").validate({
            rules:{
                itemtitle:{
                    required:true,
                },
                itempic:{
                    required:true,
                },
                shoptype:{
                    required:true,
                },
                itemsale:{
                    required:true,
                },
                itemprice:{
                    required:true,
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var arr = new FormData(document.getElementById("form-subject_items-edit"));
                $.ajax({
                    url:"{:url('operate/subject_items_edit')}",
                    type:"post",
                    data:arr,
                    async: true,
                    processData: false,
                    contentType: false,
                    dataType:"json",
                    success:function (data) {
                        if (data.code == 200){
                            layer.alert('编辑成功',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                                ,yes:function(){
                                    layer.closeAll();
                                    parent.location.reload();
                                }
                            })
                        }else {
                            layer.alert('编辑失败'+data.msg+'',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                            })
                        }

                    },
                    error:function () {
                        layer.alert('编辑失败',{
                            skin: 'layui-layer-molv' //样式类名 自定义样式
                            ,closeBtn: 0  // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: '确认'//按钮
                            ,icon: 6  // icon
                        })
                    }
                })

            }
        });

        //根据选择的类型展示相应的表格
        $("#coupon").change(function () {
            var coupon = $(this).children('option:selected').val();
            if (coupon == 1) {
                $('#coupon-content').css('display','block');
            } else if (coupon == 0) {
                $('#coupon-content').css('display','none');
            }
        });


    });
</script>

<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>